//
//  XLWinningView.m
//  XiangLove
//
//  Created by Dgh Hv on 2018/10/19.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLWinningView.h"

@interface XLWinningView ()

@property (nonatomic, assign)BOOL isCard;
@property (nonatomic, strong)NSString * awardContent;

@end

@implementation XLWinningView

- (instancetype)initWithFrame:(CGRect)frame IsCard:(BOOL)isCard AwardContent:(NSString *)awardContent
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        _isCard = isCard;
        _awardContent = awardContent;
        //绘制界面显示
        [self initUI];
    }
    
    return self;
}

-(void)initUI
{
    self.backgroundColor = RGBA(0, 0, 0, 0.3);
    UIView * backView = [[UIView alloc]init];
    ViewRadius(backView, 12);
    backView.backgroundColor = KWhiteColor;
    [self addSubview:backView];
    
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(270, 323));
        make.center.equalTo(self);
    }];

    UIImageView * topImage = [[UIImageView alloc]init];
    topImage.image = IMAGE_NAMED(@"pic_zhuanpan_zhuanpan_zhongjiang_tou_n");
    [backView addSubview:topImage];
    
    [topImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backView.mas_left).offset(0);
        make.top.equalTo(backView.mas_top).offset(0);
        make.size.mas_equalTo(CGSizeMake(270, 72));
    }];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = @"恭喜您获得以下奖品";
    titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
    titleLabel.textColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1];
    [backView addSubview:titleLabel];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(backView.mas_centerX);
        make.top.equalTo(topImage.mas_bottom).offset(9);
    }];
    
    UIView *leftLine = [[UIView alloc] init];
    leftLine.backgroundColor = RGB_HEX(0xD8D8D8);
    [backView addSubview:leftLine];
    
    [leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(titleLabel.mas_centerY);
        make.right.equalTo(titleLabel.mas_left).offset(-9);
        make.size.mas_equalTo(CGSizeMake(16, 1));
    }];
    
    UIView *rightLine = [[UIView alloc] init];
    rightLine.backgroundColor = RGB_HEX(0xD8D8D8);
    [backView addSubview:rightLine];
    
    [rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(titleLabel.mas_centerY);
        make.left.equalTo(titleLabel.mas_right).offset(9);
        make.size.mas_equalTo(CGSizeMake(16, 1));
    }];

    //奖品内容view
    UIView * centerView = [[UIView alloc]init];
    centerView.backgroundColor = RGBA_HEX(0xFFF6BD, 0.32);
    CAShapeLayer *border = [CAShapeLayer layer];
    
    border.strokeColor = RGBA_HEX(0xFFDC02, 1).CGColor;
    
    border.fillColor = nil;
    
    border.path = [UIBezierPath bezierPathWithRect:centerView.bounds].CGPath;
    
    border.frame = CGRectMake(0, 0, centerView.width, centerView.height);
    
    border.lineWidth = 1.f;
    
    border.lineCap = @"square";
    //设置线宽和线间距
    border.lineDashPattern = @[@4, @5];

    [centerView.layer addSublayer:border];
    
//
//    centerView.layer.borderWidth = 0.5;
//    centerView.backgroundColor = RGBA_HEX(0xFFDC02, 1);
//    centerView.layer.masksToBounds = YES;
    [backView addSubview:centerView];
    
    [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(backView.mas_centerX);
        make.top.equalTo(titleLabel.mas_bottom).offset(16);
        make.size.mas_equalTo(CGSizeMake(181, 130));
    }];
    
    UIImageView * awardIcon = [[UIImageView alloc]init];
    [centerView addSubview:awardIcon];
    
    if(self.isCard)
    {
        awardIcon.image = IMAGE_NAMED(@"pic_zhuanpan_ka_n");
        [awardIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(centerView.mas_top).offset(15);
            make.centerX.equalTo(centerView.mas_centerX);
            make.size.mas_equalTo(CGSizeMake(64, 64));
        }];
    }else{
        awardIcon.image = IMAGE_NAMED(@"pic_zhongjiang_dou_n");
        [awardIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(centerView.mas_top).offset(12);
            make.centerX.equalTo(centerView.mas_centerX);
            make.size.mas_equalTo(CGSizeMake(64, 64));
        }];
    }
    
    UILabel * awardLabel = [[UILabel alloc]init];
    awardLabel.text = self.awardContent;
    awardLabel.textColor = RGB_HEX(0x111111);
    awardLabel.font = SYSTEMFONT(17);
    [centerView addSubview:awardLabel];
    
    [awardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(centerView.mas_centerX);
        make.top.equalTo(awardIcon.mas_bottom).offset(14);
    }];
    
    UIButton * sureButton = [[UIButton alloc]init];
    ViewRadius(sureButton, 18);
    [sureButton setTitle:@"确定" forState:UIControlStateNormal];
    [sureButton setTitleColor:RGB_HEX(0x111111) forState:UIControlStateNormal];
    sureButton.titleLabel.font = SYSTEMFONT(16);
    sureButton.backgroundColor = RGB_HEX(0xFFDD02);
    kWeakSelf(self);
    [sureButton addTapBlock:^(UIButton *btn) {
        [weakself removeFromSuperview];
    }];
    [backView addSubview:sureButton];
    
    [sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(centerView.mas_centerX);
        make.top.equalTo(centerView.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake(160, 36));
    }];
    
    
}


@end
